
import { createRouter, createWebHashHistory, } from 'vue-router'

export const asyncRoutes = [
    {
        path: '/', redirect: '/home'
    },
    {
        path: '/home',
        component: () => import('../views/Home/Home.vue'),
        meta: {
            isShowNav: true,
            title:'码路严选——首页'
        }
    },
    {
        path: '/category',
        component: () => import('../views/Category/Category.vue'),
        meta: {
            isShowNav: true,
            title: '码路严选——分类'
        }
    },
    {
        path: '/cart',
        component: () => import('../views/Cart/Cart.vue'),
        meta: {
            isShowNav: true,
            title: '码路严选——购物车'
        }
    },
    {
        path: '/login',
        component: () => import('../views/Login/Login.vue'),
        meta: {
            isShowNav: false,
            title: '码路严选——账号管理'
        }
    },
    {
        path: '/user',
        component: () => import('../views/User/User.vue'),
        meta: {
            isShowNav: true,
            title: '码路严选——我的'
        }
    },
    {
        path: '/info/:goodsId',
        component: () => import('../views/Goods/Goods.vue'),
        meta: {
            isShowNav: false,
            title: '码路严选——商品详情'
        }
    },
    {
        path: '/addressmanage',
        component: () => import('../views/Address/AddressManage.vue'),
        meta: {
            isShowNav: false,
            title: '码路严选——地址管理'
        }
    },
    {
        path: '/addressedit',
        component: () => import('../views/Address/AddressEdit.vue'),
        meta: {
            isShowNav: false,
            title: '码路严选——编辑地址'
        }
    },
    {
        path: '/create-order',
        component: () => import('../views/Order/CreateOrder.vue'),
        meta: {
            isShowNav: false,
            title:'码路严选——生成订单'
        }
    },
    {
        path: '/my-order',
        component: () => import('../views/Order/MyOrder.vue'),
        meta: {
            isShowNav: false,
            title: '码路严选——我的订单'
        }
    },
    {
        path: '/about-us',
        component: () => import('../views/User/AboutUs.vue'),
        meta: {
            isShowNav: false,
            title: '码路严选——关于我们'
        }
    },
    {
        path: '/account-manage',
        component: () => import('../views/User/AccountManage.vue'),
        meta: {
            isShowNav: false,
            title: '码路严选——账号管理',
        }
    },
    {
        path: '/order-detail',
        component: () => import('../views/Order/OrderDetail.vue'),
        meta: {
            isShowNav: false,
            title: '码路严选——订单详情',
        }
    },
]

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        ...asyncRoutes,
        {
            path: '/:pathMatch(.*)', redirect: '/'
        },

    ]
})

// 路由前置守卫
router.beforeEach((to, from, next) => {
    // 修改页面标签的标题
    document.title = to.meta.title || '码路严选'
    next()
})

export default router